﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsCommonStorage.FileProperties
{
    public abstract class CommonBasicProperties
    {
#if NETFX_CORE || WINDOWS_PHONE
        public abstract Windows.Storage.FileProperties.BasicProperties EnvironmentProperties { get; }
#endif

        public DateTimeOffset DateModified { get { return ErrorHandler.Func(() => { return ProtectedDateModified; }); } }
        internal protected abstract DateTimeOffset ProtectedDateModified { get; }

        public DateTimeOffset ItemDate { get { return ErrorHandler.Func(() => { return ProtectedItemDate; }); } }
        internal protected abstract DateTimeOffset ProtectedItemDate { get; }

        public long Size { get { return ErrorHandler.Func(() => { return ProtectedSize; }); } }
        internal protected abstract long ProtectedSize { get; }

        public Task<IDictionary<string, object>> RetrievePropertiesAsync(IEnumerable<string> propertiesToRetrieve)
        {
            return this.ProtectedRetrievePropertiesAsync(propertiesToRetrieve);
        }
        internal protected abstract Task<IDictionary<string, object>> ProtectedRetrievePropertiesAsync(IEnumerable<string> propertiesToRetrieve);

        public async Task SavePropertiesAsync()
        {
            await ErrorHandler.AsyncAction(async() =>
            {
                await ProtectedSavePropertiesAsync().ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
        internal protected abstract Task ProtectedSavePropertiesAsync();

        public async Task SavePropertiesAsync(IEnumerable<KeyValuePair<string, object>> propertiesToSave)
        {
            await ErrorHandler.AsyncAction(async () =>
            {
                await ProtectedSavePropertiesAsync(propertiesToSave).ConfigureAwait(false);

            }).ConfigureAwait(false);
        }
        internal protected abstract Task ProtectedSavePropertiesAsync(IEnumerable<KeyValuePair<string, object>> propertiesToSave);
    }
}
